package com.vaasplus.bms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.vaasplus.bms.dao.mapper.UserMapper;
import com.vaasplus.bms.pojo.User;
import com.vaasplus.bms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: zhaoss
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findOneUser(Integer uid) {
        return userMapper.selectOneUser(uid);
    }

    @Override
    public int save(User user) {
        return userMapper.save(user);
    }

    @Override
    public int update(User user) {
        return userMapper.update(user);
    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED)
    public int deleteUserByUid(Integer uid) {
        int num = userMapper.delete(uid);
        int a = 1/0;
        return num;
    }


    @Override
    public PageInfo<User> findAllUsers(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> users = userMapper.selectAllUsers();
        // PageInfo是分页查询所有查询结果封装的类，所有的结果都从这个类取
        // 使用PageInfo包装了查询后的结果，将PageInfo交给页面
        PageInfo<User> info = new PageInfo<>(users);
        return info;
    }
}
